using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Edge.Business.Domain;
using Edge.Common.ComponentModel;
using Edge.Common.ComponentModel.Parameters;
using Edge.Common.Services;
using Edge.Common.Utils;

namespace Shop.Business.Domain.Catalog
{
    [Serializable]
    public class ProductGroupFilter : BaseFilter, ITextSearchSupported
    {
        private string keyword;
        private string catIds = string.Empty;
        private string brandIds = string.Empty;
        private string sizeIds = string.Empty;
        private Category category;
        private Brand brand;
        private GroupStatus? groupStatus;
        private bool visible = true;
        private bool inStock = false;
        private bool showInVis = false;
        private bool isBrandArt = false;
        private string brandArt;

        public string GetText()
        {
            return keyword;
        }

        public string BrandArt
        {
            get { return brandArt; }
            set { brandArt = value; }
        }

        public void SetText(string text)
        {
            keyword = text;
        }

        [Browsable(true),
         Description("Keyword"),
         Required(false),
         Category("Advanced Search"),
         Order(1)]
        [QueryParameter("keyword", IsRequired = false)]
        public string Keyword
        {
            get { return keyword; }
            set { keyword = value; }
        }
        [QueryParameter("isBrandArt", IsRequired = false)]
        public bool IsBrandArt
        {
            get { return isBrandArt; }
            set { isBrandArt = value; }
        }

        [QueryParameter("catId", IsRequired = false)]
        public string CatId
        {
            set
            {
                if (!StringUtils.IsBlankOrNull(value))
                    category = Locator.GetService<ICategoryManager>().Load(Convert.ToInt32(value));
            }
        }

        [QueryParameter("brandId", IsRequired = false)]
        public string BrandId
        {
            set
            {
                if (!StringUtils.IsBlankOrNull(value))
                    brand = Locator.GetService<IBrandManager>().Load(Convert.ToInt32(value));
            }
        }

        public Category Category
        {
            get { return category; }
            set { category = value; }
        }

        public Brand Brand
        {
            get { return brand; }
            set { brand = value; }
        }

        [QueryParameter("status", IsRequired = false)]
        public GroupStatus? GroupStatus
        {
            get { return groupStatus; }
            set { groupStatus = value; }
        }

        public bool Visible
        {
            get { return visible; }
            set { visible = value; }
        }

        public bool ShowInVis
        {
            get { return showInVis; }
            set { showInVis = value; }
        }

        [QueryParameter("inStock", IsRequired = false)]
        public bool InStock
        {
            get { return inStock; }
            set { inStock = value; }
        }

        [QueryParameter("catList", IsRequired = false)]
        public string CatIds
        {
            get
            {
                if (category != null)
                {
                    if (!catIds.Contains(category.Id.ToString()))
                    {
                        catIds += "," + category.Id.ToString();
                    }
                }
                return catIds;
            }
            set { catIds = value; }
        }
        [QueryParameter("brandList", IsRequired = false)]
        public string BrandIds
        {
            get
            {
                if (brand != null)
                {
                    if (!brandIds.Contains(brand.Id.ToString()))
                    {
                        brandIds += "," + brand.Id.ToString();
                    }
                }
                return brandIds;
            }
            set { brandIds = value; }
        }

        [QueryParameter("sizeList", IsRequired = false)]
        public string SizeIds
        {
            get
            {
                return sizeIds;
            }
            set { sizeIds = value; }
        }
    }
}